# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
set(libraryTargetName iotfleetwise.datacollection)

# The alias name is what other targets will use as a dependency
set(libraryAliasName IoTFleetWise::DataCollection)

set(SRCS
  src/CollectionSchemeIngestion.cpp
  src/CollectionSchemeIngestionList.cpp
)

add_library(
  ${libraryTargetName}
  # STATIC or SHARED left out to depend on BUILD_SHARED_LIBS
  ${SRCS}
)

find_path(JSONCPP_INCLUDE_DIR "json/json.h" PATH_SUFFIXES "jsoncpp")
find_library(JSONCPP_LIBRARY NAMES jsoncpp)

target_include_directories(${libraryTargetName} PUBLIC include ${JSONCPP_INCLUDE_DIR})

find_package(Boost 1.71.0 REQUIRED COMPONENTS filesystem)

target_link_libraries(
  ${libraryTargetName}
  Boost::filesystem
  IoTFleetWise::DataManagementTypes
  IoTFleetWise::OffboardConnectivityAwsIot
  IoTFleetWise::Proto
  IoTFleetWise::Platform::Linux
  IoTFleetWise::Vehiclenetwork
)

add_library(${libraryAliasName} ALIAS ${libraryTargetName})

### Install ###

install(TARGETS ${libraryTargetName} DESTINATION lib)

install(
  FILES
  include/CANInterfaceIDTranslator.h
  include/CollectionSchemeIngestion.h
  include/CollectionSchemeIngestionList.h
  include/ICollectionScheme.h
  include/ICollectionSchemeList.h
  DESTINATION include
)

if(${BUILD_TESTING})
  message(STATUS "Building tests for ${libraryTargetName}")

  set(
      testSources
  )

   # Add the executable targets
  foreach(testSource ${testSources})
    # Need a name for each exec so use filename w/o extension
    get_filename_component(testName ${testSource} NAME_WE)

    add_executable(${testName} ${testSource})

    # Link to the project library and testing library main
    target_link_libraries(
      ${testName}
      PRIVATE
      ${libraryTargetName}
      IoTFleetWise::TestingSupport
    )

    target_include_directories(
      ${testName}
      PRIVATE
      include
      test/include)

    add_unit_test(${testName})
    add_valgrind_test(${testName})
    install(TARGETS ${testName} RUNTIME DESTINATION bin/tests)

  endforeach()

endif()
